<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Admin\Controller;
use Think\Controller;
class AdminController extends Controller {
   
    function showlist(){
      
        $info = D('Admin')->where('id != 1')->select();
        $this->assign('admin',$info);
        $this->display();
    }
	function add(){
		if(empty($_POST)){
			$info =D('Rule')->select();
            $this->assign('show',$info);
			$this->display();
			}else{
				$where['adname'] = $_POST['adname'];
				$ad = D('Admin')->where($where)->find();
				if($ad>0){
					$this->error('该用户已存在');
					}else{
						$id=$_POST['roleid'];
						$info1 =D('Rule')->find($id);
						$data['rolename'] = $info1['role_name'];
						$data['adname']=$_POST['adname'];
						$data['adpsd'] =MD5($_POST['adpsd']);
						$data['roleid']=$_POST['roleid'];
						$info = D(Admin)->add($data);
						if($info>0){
							$this->success('添加成功');
							}else{
								$this->error('添加失败');
							}
						}
				}
		}
	function update(){
		 if(empty($_POST)){
				$infolist = D('Admin')->select($_GET['id']);
				$info =D('Rule')->select();
				$this->assign('show',$infolist);
           		$this->assign('list',$info);
				$this->display();
			}else{
				$where['id'] = $_GET['id'];
				$id=$_POST['roleid'];
				$info1 =D('Rule')->find($id);
				$data['adname']=$_POST['adname'];
				$data['adpsd'] =MD5($_POST['adpsd']);
				$data['rolename'] = $info1['role-name'];
				$info = D(Admin)->where($where)->save($data);
				if($info>0){
					$this->success('修改成功');
				}else{
					$this->error('修改失败');
				}
			}
		}
	function dele(){
		$where['id']=$_GET['id'];
		$dele = D('Admin')->where($where)->delete();
			if($dele){
				$this->success('删除成功');
				}else{
					$this->error('删除失败');
			}
		}	
}

